package initialize

import (
	"net/http"
	"portal_api/middleware"
	"portal_api/models/response"
	"portal_api/router"

	"github.com/gin-gonic/gin"
)

func InitRouter(isDebug bool) *gin.Engine {

	// 开启gin的debug模式
	if isDebug {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}

	r := gin.Default()
	r.GET("/health", func(c *gin.Context) {
		c.JSON(http.StatusOK, response.Response{
			Code:    http.StatusOK,
			Message: "success",
		})
	})
	r.Use(middleware.Cors())
	apiGroup := r.Group("/p/v1")
	router.InitApiRouter(apiGroup)
	return r
}
